package Operation;

import Book.BookList;

import java.util.Scanner;

//借阅图书
public class BorrowBook implements IOperation {

    @Override
    public void work(BookList bookList) {
        System.out.println("借出图书.....");
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你要借出的图书的名字：");
        String bookName = sc.nextLine();
        int count = bookList.getUsedSize();
        for (int i = 0; i < count; i++) {
            if(bookList.getBooks()[i].getName().equals(bookName)){
                if(!bookList.getBooks()[i].getIsBorrow()){
                    bookList.getBooks()[i].setBorrowed(true);
                    System.out.println("借书成功。");
                    return;
                }else {
                    System.out.println("该书已经被借出，无法借出！！！");
                    return;
                }
            }
        }
        System.out.println("没有找到该书，无法借阅！！");
    }
}
